﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RuleOfReady.Core.DomainModels.Tiles;

namespace RuleOfReady.Core.DomainModels.Sets
{
    public class PartialSequenceComparer : IEqualityComparer<MahjongPartialSequence>
    {
        public bool Equals(MahjongPartialSequence x, MahjongPartialSequence y)
        {
            if (Object.ReferenceEquals(x, null))
                return false;
            if (Object.ReferenceEquals(y, this))
                return true;
            bool isSame = (x.WaitingTiles.SequenceEqual(y.WaitingTiles));
            return isSame;
        }

        public int GetHashCode(MahjongPartialSequence obj)
        {

            int hashCode = 0;
            foreach (MahjongTile tile in obj.WaitingTiles)
                hashCode ^= tile.GetHashCode(); 
            return hashCode;
        }
    }
}
